﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Hotel.Classes.Helper;
using Hotel.Models.Entity;

namespace Hotel.Models.DataAccess
{
    public class DACash
    {
        public static Cash GetCash()
        {
            Cash cash = new Cash();
            DataTable dt;
            using (DBManager dbManager = new DBManager("stp_Get_Cash"))
            {
                dt = dbManager.GetDatatable();
            }
            if (dt.Rows.Count > 0)
            {
                cash.PkCashId = DataHelper.GetInt(dt.Rows[0], "PK_CashID");
                cash.TimeCheck = DataHelper.GetInt(dt.Rows[0], "TimeCheck");
                cash.Currency = DataHelper.Get(dt.Rows[0], "Currency");
                cash.ConvertPrice = DataHelper.GetDouble(dt.Rows[0], "ConvertPrice");
                cash.Rounding = DataHelper.GetInt(dt.Rows[0], "Rounding");
                cash.MoreOneHour = DataHelper.GetInt(dt.Rows[0], "MoreOneHour");
                cash.MoreTwoHour = DataHelper.GetInt(dt.Rows[0], "MoreTwoHour");
                cash.MoreThreeHour = DataHelper.GetInt(dt.Rows[0], "MoreThreeHour");
                cash.FreeHour = DataHelper.GetInt(dt.Rows[0], "FreeHour");
                return cash;
            }
            else
            {
                return null;
            }
        }

        public static bool SaveCash(Cash cash)
        {
            using (DBManager dbManager = new DBManager("stp_Create_Cash"))
            {
                try
                {
                    dbManager.Add("p_TimeCheck", cash.TimeCheck);
                    dbManager.Add("p_Currency", cash.Currency);
                    dbManager.Add("p_ConvertPrice", cash.ConvertPrice);
                    dbManager.Add("p_Rounding", cash.Rounding);
                    dbManager.Add("p_MoreOneHour", cash.MoreOneHour);
                    dbManager.Add("p_MoreTwoHour", cash.MoreTwoHour);
                    dbManager.Add("p_MoreThreeHour", cash.MoreThreeHour);
                    dbManager.Add("p_FreeHour", cash.FreeHour);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
                
            }
        }
    }
}